package com.xian.ai.code.core.saver;

import cn.hutool.core.util.StrUtil;
import com.xian.ai.code.ai.model.HtmlCodeResult;
import com.xian.ai.code.exception.ErrorCode;
import com.xian.ai.code.exception.ThrowUtils;
import com.xian.ai.code.model.enums.CodeGenTypeEnum;

/**
 * @ClassName HtmlCodeFileSaveTemplate
 * @Description TODO
 * @Author Zhangxn
 * @Version 1.0
 */
public class HtmlCodeFileSaveTemplate extends CodeFileSaveTemplate<HtmlCodeResult>{
    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void validateInput(HtmlCodeResult result) {
        super.validateInput(result);
        ThrowUtils.throwIf(StrUtil.isBlank(result.getHtmlCode()), ErrorCode.PARAMS_ERROR,"html代码不能为空");
    }

    @Override
    protected void saveFiles(HtmlCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath,"index.html",result.getHtmlCode());

    }
}
